const arr = ["a","b","c","d","e"];

// 回溯算法
function main(arr){
    if(arr.length === 1) return [arr[0]];
    let res = [];
    for(let i = 0; i < arr.length; ++i){
        const newArray = [...arr.slice(0, i),...arr.slice(i + 1)];
        res = res.concat(main(newArray).map(item => arr[i] + item));
    }
    return res;
}
// 5! = 120,正解
console.log(new Set(main(arr)).size)
